﻿function SelectAll(tempControl) {
    var theBox = tempControl;
    var xState = theBox.checked;
    var elem = theBox.form.elements;
    for (var i = 0; i < elem.length; i++) {
        if (elem[i].type == "checkbox" && elem[i].id != theBox.id) {
            if (elem[i].checked != xState) {
                elem[i].click();
            }
        }
    }
}

var a;

function CheckValuePiece() {
    var form1 = document.forms['form1'];
    if (form1.GoPage.value == "") {
        alert("请输入跳转的页码！");
        form1.GoPage.focus();
        return false;
    }
    return true;
}
function CheckAll() {
    var form1 = document.forms['form1'];
    if (a == 1) {
        for (var i = 0; i < form1.elements.length; i++) {
            var e = form1.elements[i];
            e.checked = false;
        }
        a = 0;
    }
    else {
        for (var i = 0; i < form1.elements.length; i++) {
            var e = form1.elements[i];
            e.checked = true;
        }
        a = 1;
    }
}
function CheckModify() {
    var modifynumber = 0;
    var form1 = document.forms['form1'];
    for (var i = 0; i < form1.elements.length; i++) {
        var e = form1.elements[i];
        if (e.Name != "CheckBoxAll" && e.id.startsWith('GVData')) {
            if (e.checked == true) {
                modifynumber = modifynumber + 1;
            }
        }
    }
    if (modifynumber == 0) {
        alert("请至少选择一项！");
        return false;
    }
    if (modifynumber > 1) {
        alert("只允许选择一项！");
        return false;
    }

    return true;
}

function CheckUpdateAll() {
    var number = 0;
    var form1 = document.forms['form1'];
    for (var i = 0; i < form1.elements.length; i++) {
        var e = form1.elements[i];
        if (e.Name != "CheckBoxAll") {
            if (e.checked == true) {
                number = number + 1;
            }
        }
    }
    if (number == 0) {
        alert("请选择需要更新的项！");
        return false;
    }
    if (window.confirm("你确认更新吗？")) {
        return true;
    }
    else {
        return false;
    }
}

function CheckDel() {
    var number = 0;
    var form1 = document.forms['form1'];
    for (var i = 0; i < form1.elements.length; i++) {
        var e = form1.elements[i];
        if (e.Name != "CheckBoxAll") {
            if (e.checked == true) {
                number = number + 1;
            }
        }
    }
    if (number == 0) {
        alert("请选择需要删除的项！");
        return false;
    }
    if (window.confirm("你确认删除吗？")) {
        return true;
    }
    else {
        return false;
    }
}

function CheckConfig() {
    var number = 0;
    var form1 = document.forms['form1'];
    for (var i = 0; i < form1.elements.length; i++) {
        var e = form1.elements[i];
        if (e.Name != "CheckBoxAll") {
            if (e.checked == true) {
                number = number + 1;
            }
        }
    }
    if (number == 0) {
        alert("请选择需要设置的项！");
        return false;
    }
    if (window.confirm("你确认将设置选中项吗？")) {
        return true;
    }
    else {
        return false;
    }
}

function CheckSend() {
    var number = 0;
    var form1 = document.forms['form1'];
    for (var i = 0; i < form1.elements.length; i++) {
        var e = form1.elements[i];
        if (e.Name != "CheckBoxAll") {
            if (e.checked == true) {
                number = number + 1;
            }
        }
    }
    if (number == 0) {
        alert("请选择需要发送的项！");
        return false;
    }
    if (window.confirm("你确认将发送选中项吗？")) {
        return true;
    }
    else {
        return false;
    }
}

function CheckChangePwd() {
    var number = 0;
    var form1 = document.forms['form1'];
    for (var i = 0; i < form1.elements.length; i++) {
        var e = form1.elements[i];
        if (e.Name != "CheckBoxAll") {
            if (e.checked == true) {
                number = number + 1;
            }
        }
    }
    if (number == 0) {
        alert("请选择需要设置初始密码的项！");
        return false;
    }
    if (window.confirm("你确认将选中项设置初始密码为：【888888】吗？")) {
        return true;
    }
    else {
        return false;
    }
}

function PrintTable() {
    document.getElementById("PrintHide").style.visibility = "hidden";
    print();
    document.getElementById("PrintHide").style.visibility = "visible";
}

function collapse(img, objName) {
    var obj;
    obj = document.getElementById(objName);
    var k;
    k = obj.rows.length;
    if (img.src.indexOf('open') != -1) {
        img.src = img.src.replace('open', 'close');
        for (i = 1; i < k; i++) {
            obj.rows[i].style.display = 'none';
        }
    } else {
        img.src = img.src.replace('close', 'open');
        for (i = 1; i < k; i++) {
            obj.rows[i].style.display = '';
        }
    }
}

function fieldValid() {
    //return $('#check').kendoValidator().data('kendoValidator').validate();
    return;
}

function decodeBase64(strIn) {
    if (!strIn.length || strIn.length % 4)
        return null;
    var str64 =
        "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var index64 = [];
    for (var i = 0; i < str64.length; i++)
        index64[str64.charAt(i)] = i;
    var c0, c1, c2, c3, b0, b1, b2;
    var len = strIn.length;
    var len1 = len;
    if (strIn.charAt(len - 1) == '=')
        len1 -= 4;
    var result = [];
    for (var i = 0, j = 0; i < len1; i += 4) {
        c0 = index64[strIn.charAt(i)];
        c1 = index64[strIn.charAt(i + 1)];
        c2 = index64[strIn.charAt(i + 2)];
        c3 = index64[strIn.charAt(i + 3)];
        b0 = (c0 << 2) | (c1 >> 4);
        b1 = (c1 << 4) | (c2 >> 2);
        b2 = (c2 << 6) | c3;
        result.push(b0 & 0xff);
        result.push(b1 & 0xff);
        result.push(b2 & 0xff);
    }
    if (len1 != len) {
        c0 = index64[strIn.charAt(i)];
        c1 = index64[strIn.charAt(i + 1)];
        c2 = strIn.charAt(i + 2);
        b0 = (c0 << 2) | (c1 >> 4);
        result.push(b0 & 0xff);
        if (c2 != '=') {
            c2 = index64[c2];
            b1 = (c1 << 4) | (c2 >> 2);
            result.push(b1 & 0xff);
        }
    }
    return result;
}

function EnterToTab() {
    if (window.event.keyCode == 13) {
        window.event.keyCode = 9;
    }
}

function Disable(str) {
    $(str).attr('style', 'display:none;');
}
function Enable(str) {
    $(str).attr('style', 'display:block;');
}
function FormatAfterDotNumber(ValueString, nAfterDotNum) {
    var ValueString, nAfterDotNum;
    var resultStr, nTen;
    ValueString = "" + ValueString + "";
    strLen = ValueString.length;
    dotPos = ValueString.indexOf(".", 0);
    if (dotPos == -1) {
        resultStr = ValueString + ".";
        for (i = 0; i < nAfterDotNum; i++) {
            resultStr = resultStr + "0";
        }
        return resultStr;
    }
    else {
        if ((strLen - dotPos - 1) >= nAfterDotNum) {
            nAfter = dotPos + nAfterDotNum + 1;
            nTen = 1;
            for (j = 0; j < nAfterDotNum; j++) {
                nTen = nTen * 10;
            }
            resultStr = Math.round(parseFloat(ValueString) * nTen) / nTen;
            return resultStr;
        }
        else {
            resultStr = ValueString;
            for (i = 0; i < (nAfterDotNum - strLen + dotPos + 1); i++) {
                resultStr = resultStr + "0";
            }
            return resultStr;
        }
    }
} 